<template>
  <d-scroll-view  @refresherrefresh="getDetail" :refresher-triggered="triggered">
    <proj-detail-layout form-title="项目基础信息表">
      <d-forms label-width="200rpx">
        <d-forms-item label="项目名称" :input="form.projectName"></d-forms-item>
        <d-forms-item label="项目编号" :input="form.projectNumber"></d-forms-item>
        <d-forms-item label="项目类型" :input="form.projectTypeName"></d-forms-item>
        <d-forms-item label="项目级别" :input="form.projectGradeName"></d-forms-item>
        <d-forms-item label="建设单位" :input="form.constructionUnitName"></d-forms-item>
        <d-forms-item label="最终用户" :input="form.useUnitName"></d-forms-item>
        <view>
          <view class="form-title-1">建设内容</view>
          <d-card>
            <d-forms-item disabled :input="form.constructionContent"></d-forms-item>
          </d-card>
        </view>
        <d-forms-item label="是否招投标" :input="form.isTenderedName"></d-forms-item>
        <d-forms-item :type="DFormInputType.DATE" label="招标时间" :input="form.plannedBiddingTime"></d-forms-item>
        <d-forms-item :type="DFormInputType.DATE" label="中标时间" :input="form.bidTime"></d-forms-item>
        <view class="mt10">
          <tab-title>合同情况</tab-title>
          <d-forms-item label="合同名称" :input="form.contractName"></d-forms-item>
          <d-forms-item label="合同编号" :input="form.contractNumber"></d-forms-item>
          <d-forms-item :type="DFormInputType.AMOUNT" label="含税合同金额" :input="form.amountIncludingTax"></d-forms-item>
          <d-forms-item :type="DFormInputType.DATE" label="合同起始时间" :input="form.startTime"></d-forms-item>
          <d-forms-item :type="DFormInputType.DATE" label="合同截止时间" :input="form.endTime"></d-forms-item>
          <view>
            <view class="form-title-1">计划回款周期</view>
            <view v-if="form.plannedPaymentList && form.plannedPaymentList.length">
              <view class="mb10" v-for="(item, idx) in form.plannedPaymentList" :key="item.id">
                <d-card>
                  <d-forms-item disabled label="回款批次" :input="item.paymentBatch"></d-forms-item>
                  <d-forms-item disabled :type="DFormInputType.AMOUNT" label="金额" :input="item.amount"></d-forms-item>
                  <d-forms-item disabled :type="DFormInputType.DICT" :dict-type="PM_DICT_TYPE.PAYMENT_MODE" label="支付方式" :input="item.paymentMode"></d-forms-item>
                  <d-forms-item disabled label="回款日期" :input="item.paymentTime"></d-forms-item>
                  <d-forms-item disabled label="开户银行" :input="item.accountsBank"></d-forms-item>
                  <d-forms-item disabled label="户名" :input="item.accountName"></d-forms-item>
                  <d-forms-item disabled label="回款账户" :input="item.account"></d-forms-item>
                  <d-forms-item disabled label="回款条件" :input="item.terms"></d-forms-item>
                  <d-forms-item disabled label="备注" :input="item.remarks"></d-forms-item>
                </d-card>
              </view>
            </view>
            <view v-else style="text-align: center">暂无</view>
          </view>
        </view>
        <view class="mt10">
          <tab-title>项目完成情况</tab-title>
          <d-forms-item :type="DFormInputType.DATE" label="初验日期" :input="form.preliminaryAcceptanceDate"></d-forms-item>
          <view>
            <view class="form-title-1">初验报告</view>
            <d-card>
              <pm-file-upload v-if="form.preliminaryAcceptanceReport" readonly :files="form.preliminaryAcceptanceReport"></pm-file-upload>
              <view v-else>暂无</view>
            </d-card>
          </view>
          <d-forms-item :type="DFormInputType.DATE" label="终验日期" :input="form.finalAcceptanceDate"></d-forms-item>
          <view>
            <view class="form-title-1">终验报告</view>
            <d-card>
              <pm-file-upload v-if="form.finalAcceptanceReport" readonly :files="form.finalAcceptanceReport"></pm-file-upload>
              <view v-else>暂无</view>
            </d-card>
          </view>
          <d-forms-item label="服务开始时间" :type="DFormInputType.DATE" :input="form.operationMaintenanceStartTime"></d-forms-item>
          <d-forms-item label="服务停止时间" :type="DFormInputType.DATE" :input="form.operationMaintenanceEndTime"></d-forms-item>
          <d-forms-item label="运维期限" :input="form.operationMaintenancePeriod"></d-forms-item>
        </view>
        <view class="mt10">
          <tab-title>项目组成员</tab-title>
          <d-forms-item label="销售经理" :input="form.salesManager"></d-forms-item>
          <d-forms-item label="项目经理" :input="form.projectManager"></d-forms-item>
          <d-forms-item label="服务负责人" :input="form.headOfService"></d-forms-item>
        </view>
      </d-forms>
    </proj-detail-layout>
  </d-scroll-view>
</template>

<script setup lang="ts">
import {PM_DICT_TYPE} from "@/utils/pmDict";
import {usePmProjectApi} from "@/api/pm/project/project";
import {DFormInputType} from "@/utils/enum";

const initForm = {
  projectName: null,
  projectNumber: null,
  projectGrade: null,
  projectGradeName: null,
  projectType: null,
  projectTypeName: null,
  constructionUnit: null,
  constructionUnitName: null,
  useUnit: null,
  useUnitName: null,
  constructionContent: null,
  isTendered: null,
  plannedBiddingTime: null,
  bidTime: null,
  contractName: null,
  contractNumber: null,
  amountIncludingTax: null,
  startTime: null,
  endTime: null,
  plannedPaymentList: null,
  preliminaryAcceptanceDate: null,
  preliminaryAcceptanceReport: null,
  finalAcceptanceDate: null,
  finalAcceptanceReport: null,
  operationMaintenanceStartTime: null,
  operationMaintenanceEndTime: null,
  operationMaintenancePeriod: null,
  salesManager: null,
  projectManager: null,
  headOfService: null,
}
const form = ref<ProjectDetail>(initForm);
const triggered = ref<boolean>(false);
function getDetail() {
  if (projectNumber.value) {
    triggered.value = true;
    usePmProjectApi().getProjectDetailInfo(projectNumber.value).then(res => {
      if (res.code === 0) {
        form.value = res.data || initForm;
      }
    }).finally(() => {
      triggered.value = false;
    })
  }
}

const projectNumber = ref<string>();
onLoad((query) => {
  projectNumber.value = query['project_number'];
  getDetail()
})
</script>

<style scoped lang="scss">

</style>
